package com.wss.day06.string;

import java.util.Arrays;
import java.util.Comparator;

/**
 * @author wangshaoshuai
 * @desc TODO
 * @date 2025/4/26
 */
public class Test02 {
    public static void main(String[] args) {

        String[] arr = {"nba", "abc", "cba", "zz", "qq", "haha"};


        String[] arr1 = arr.clone();
        Arrays.sort(arr1);
        System.out.println("方式一排序结果: " + Arrays.toString(arr1));


        String[] arr2 = arr.clone();
        Arrays.sort(arr2, new Comparator<String>() {
            @Override
            public int compare(String s1, String s2) {
                return s1.compareTo(s2);
            }
        });
        System.out.println("方式二排序结果: " + Arrays.toString(arr2));


        int[] intArr = {1, 2, 3};
        StringBuilder sb1 = new StringBuilder();
        sb1.append("[");
        for (int i = 0; i < intArr.length; i++) {
            if (i != intArr.length - 1) {
                sb1.append(intArr[i]).append(", ");
            } else {
                sb1.append(intArr[i]);
            }
        }
        sb1.append("]");
        System.out.println("练习 1 结果: " + sb1.toString());


        String str = "hello";
        StringBuilder sb2 = new StringBuilder(str);
        String reversedStr = sb2.reverse().toString();
        System.out.println("练习 2 结果: " + reversedStr);


        String testStr1 = "abc";
        String testStr2 = "aba";
        System.out.println("练习 3 结果 - " + testStr1 + ": " + isSymmetric(testStr1));
        System.out.println("练习 3 结果 - " + testStr2 + ": " + isSymmetric(testStr2));
    }

    public static boolean isSymmetric(String str) {
        StringBuilder sb = new StringBuilder(str);
        return str.equals(sb.reverse().toString());
    }
}
